package com.jiaoyou.baojian.http;

import android.content.Context;
import android.os.Environment;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.jiaoyou.baojian.BaojianApplication;
import com.jiaoyou.baojian.MainActivity;
import com.jiaoyou.baojian.activity.RoomActivity;
import com.jiaoyou.baojian.http.response.BaseResponse;
import com.jiaoyou.baojian.utils.ACache;
import com.jiaoyou.baojian.utils.ParameterizedTypeImpl;

import java.io.File;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by DemonZYM on 17/5/10.
 */

public class Utils {
    private static Gson GSON = new Gson();
    public static <T> BaseResponse<T> fromJsonObject(BaseResponse<T> response, Class<T> clazz) {
        Type type = new ParameterizedTypeImpl(BaseResponse.class, new Class[]{clazz});
        return GSON.fromJson(GSON.toJson(response), type);
    }
    public static <T> BaseResponse<List<T>> fromJsonArray(BaseResponse<T> response, Class<T> clazz) {
        // 生成List<T> 中的 List<T>
        Type listType = new ParameterizedTypeImpl(List.class, new Class[]{clazz});
        // 根据List<T>生成完整的Result<List<T>>
        Type type = new ParameterizedTypeImpl(BaseResponse.class, new Type[]{listType});
        return GSON.fromJson(GSON.toJson(response), type);
    }
}
